import { defineStore } from 'pinia'
import { ref } from 'vue'
import type { IcartItem } from '@/types/cart'

export const useOrder = defineStore('order', () => {
  const orderStatusTabs = ref([
    { orderState: -1, name: '全部', text: '', className: '', icon: '' },
    {
      orderState: 0,
      name: '待付款',
      text: '待付款',
      className: 'status01',
      icon: 'icon-daifukuan',
      list: [],
    },
    {
      orderState: 1,
      name: '已下单',
      text: '已下单',
      className: 'status02',
      icon: 'icon-dingdanzhuangtai-fahuozhong',
      list: [],
    },
    {
      orderState: 2,
      name: '制作中',
      text: '制作中',
      className: 'status03',
      icon: 'icon-daifahuo',
      list: [],
    },
    {
      orderState: 3,
      name: '配送中',
      text: '配送中',
      className: 'status03',
      icon: 'icon-daifahuo',
      list: [],
    },
    {
      orderState: 4,
      name: '已完成',
      text: '已完成',
      className: 'status04',
      icon: 'icon-yiwancheng',
      list: [],
    },
    { orderState: 5, name: '已退款', text: '', className: 'status05', icon: '', list: [] },
    { orderState: 6, name: '已取消', text: '', className: 'status05', icon: '', list: [] },
  ])
  const getorderStatusTabs = () => {
    return orderStatusTabs.value
  }
  const orderStatusTabsName = (val: number): string => {
    return orderStatusTabs.value.find((item: any) => item.orderState === val)?.['name'] || ''
  }
  const orderStatusTabsClassName = (val: number): string => {
    return orderStatusTabs.value.find((item: any) => item.orderState === val)?.['className'] || ''
  }
  const orderData = ref<IcartItem[]>([] as IcartItem[])

  const addOrderData = (records: IcartItem[]) => {
    orderData.value = records
  }
  const clearAll = () => {
    orderData.value = []
  }

  const getOrderData = () => {
    return orderData.value
  }

  return {
    orderData,
    getorderStatusTabs,
    orderStatusTabsName,
    orderStatusTabsClassName,
    getOrderData,
    clearAll,
    addOrderData,
  }
})
